<script type="text/html" template>
  <link rel="stylesheet" href="{{ layui.setter.base }}style/css/reset.css">
  <link rel="stylesheet" href="{{ layui.setter.base }}style/page.css">
  <link rel="stylesheet" href="{{ layui.setter.base }}style/css/patrol/cashForm.css">
</script>
<style scoped>
  .newProjectBtn{
    width: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 11px;
    margin: 0;
    padding: 0 5px;
    border: 0;
    text-align: center;
    line-height: 22px;
    height: 22px;
  }
   .layui-card-header .layui-icon{
    margin-top:0;
  }
  </style>
<div class="layui-fluid">
  <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
    <div class="layui-form-item">
      <div class="layui-inline">
        <button class="newProjectBtn layui-btn layuiadmin-btn-useradmin" data-type="addproduct">
          <i class="layui-icon layui-icon-add-circle" style="font-size: 14px; color: #1E9FFF;"></i>
          <span>新建项目</span>
        </button>
        </button>
      </div>
    </div>
  </div>

  <div class="layui-card-body">
    <form class="layui-form formData_llp2" lay-filter="app-content-comment">
      <div class="layui-form-item itemOfTwo">

        <div class="firestBreak layui-col-md2 layui-col-xs2 layui-col-sm2">
          <div class="layui-inline">
            <span class="sbbh labelinp" och="DEVNumber">项目名称：</span>
            <input id="Number" name="" class="inp xjone" lay-ignore autocomplete="off"
              style="border: 1px solid #e6e6e6;height: 22px;width: 70px;">
            </input>
          </div>
        </div>

        <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
          <div class="layui-inline">
            <span class="sbbh labelinp" och="DEVNumber">项目说明：</span>
            <input id="Number" name="" class="inp xjTwo" lay-ignore autocomplete="off"
              style="border: 1px solid #e6e6e6;height: 22px;width: 70px;">
            </input>
          </div>
        </div>

        <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
          <div class="layui-inline">
            <span class="sbbh labelinp" och="DEVNumber">单位:</span>
            <input id="Number" name="" class="inp xjThree" lay-ignore autocomplete="off"
              style="border: 1px solid #e6e6e6;height: 22px;width: 70px;">
            </input>
          </div>
        </div>

        <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
          <div class="layui-inline">
            <span class="sbbh labelinp" och="DEVNumber">最低标准值:</span>
            <input id="Number" name="" class="inp xjFour" lay-ignore autocomplete="off"
              style="border: 1px solid #e6e6e6;height: 22px;width: 70px;">
            </input>
          </div>
        </div>

        <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
          <div class="layui-inline">
            <span class="sbbh labelinp" och="DEVNumber">最高标准值:</span>
            <input id="Number" name="" class="inp xjllp" lay-ignore autocomplete="off"
              style="border: 1px solid #e6e6e6;height: 22px;width: 70px;">
            </input>
          </div>
        </div>

        <div class="layui-col-md2 layui-col-xs2 layui-col-sm2">
          <button type="button" data-lang="Inquire"
            class="ChaXunButton labelbtn layui-btn layui-btn-radius layui-btn-primary" data_cn="高级搜索"
            data_en="advanced search" lay-submit lay-filter="query" id="queryButton2">
            <i class="layui-icon layui-icon-search" style="font-size: 10px; color: #FFF;"></i>
            <span>查询</span>
          </button>
        </div>
      </div>
    </form>
    <table class="layui-table" id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
    <!-- 删除按钮 -->
    <button class="newProjectBtn layui-btn layuiadmin-btn-useradmin" data-type="deleteProject" style="background:#FF4C4C;margin-top:12px;">
          <i class="layui-icon layui-icon-delete" style="font-size: 14px; color: #fff;"></i>
          <span style="color:#fff">删除</span>
    </button>
  </div>


  <script type="text/html" id="barDemo">
     <i class="EditElement layui-icon layui-icon-edit" style="cursor:pointer;margin-right:10px" lay-event="edit"></i>
     <i class="EditElement layui-icon layui-icon-delete" style="cursor:pointer" lay-event="delete"></i>
     {{#  if(d.tcInspIsdel=="0"){ }}
     
        <i class="layui-icon layui-icon-pause" style="padding-left: 10px; cursor:pointer;font-size:13px;" lay-event="toogele"></i>
     {{#  } else  if(d.tcInspIsdel=="1"){ }}

       <i class="layui-icon layui-icon-play" style="padding-left: 10px;font-size:13px;"   lay-event="toogele1"></i>

     {{#  } else  if(d.state=="reject"){ }}
     <span>-</span>

     {{#  } else  { }}

     {{#  } }}
</script>

  <script>
    layui.use(['admin', 'form', 'user', 'table', 'api', 'laytpl', 'utill', 'laydate'], function () {
      var $ = layui.$,
        admin = layui.admin,
        view = layui.view,
        api = layui.api,
        table = layui.table,
        setter = layui.setter,
        laytpl = layui.laytpl,
        utill = layui.utill,
        laydate = layui.laydate,
        form = layui.form;
      rander();
      function rander() {
         // 巡检项目高查
        $("#queryButton2").click(function () {
          var one = $(".xjone").val();
          var two = $(".xjTwo").val();
          var three = $(".xjThree").val();
          var four = $(".xjFour").val();
          var five = $(".xjllp").val();
          table.reload('#LAY-app-content-list', {
            where: {
              tcInspName: one,
              tcInspDsc: two,
              tcInspUnit: three,
              tcInspMin: four,
              tcInspMax: five
            },
            page: {
              curr: 1
            }
          })
        })
        table.on("tool(LAY-app-content-list)", function (obj) {
          var data = obj.data;
          if (obj.event === "edit") {
            admin.popup({
              title: "项目编辑",
              area: ['344px', '390px'],
              id: "LAY-popup-user-add",
              success: function (layero, index) {
                view(this.id).render("patrol/alert/EditProject", data).done(function () {
                  //  点击取消按钮关闭
                  $(".layui-input-block").on("click", ".btn2", function () {
                    layer.close(index);
                  });
                  // 数据回显
                  form.render(null, "layuiadmin-form-tags");
                  form.val("layuiadmin-form-tags", {
                    tcInspName: data.tcInspName,
                    tcInspUnit: data.tcInspUnit,
                    tcInspMax: data.tcInspMax,
                    tcInspMin: data.tcInspMin,
                    tcInspDsc: data.tcInspDsc
                  });
                  var id = data.id;
                  //监听项目修改
                  form.on("submit(layuiadmin-app-form-submit)", function (data) {
                    var field = data.field; //获取提交的字段
                    field.tcInspId = obj.data.tcInspId;
                    field = JSON.stringify(field);
                    admin.req({
                      url: api.host + api.batchUpdateProject,
                      data: field,
                      type: "POST",
                      dataType: "json",
                      contentType: "application/json",
                      done: function (res) {
                        layui.table.reload("#LAY-app-content-list"); //重载表格
                        layer.close(index); //执行关闭
                        layer.msg(res.message);
                      }
                    });
                  });
                  table.render();
                });
              }
            });
          } else if (obj.event === "toogele") {
            // 禁用
            var a = obj.data.tcInspId;
            var arr = [];
            arr.push(a);
            admin.req({
              url: api.host + api.batchUpdateIsDelN,
              data: JSON.stringify(arr),
              type: "POST",
              dataType: "json",
              contentType: "application/json",
              done: function (res) {
                layer.msg(res.message);
                layui.table.reload("#LAY-app-content-list"); //重载表格
              }
            });
          } else if (obj.event === "toogele1") {
            // 启用
            var a = obj.data.tcInspId;
            var arr = [];
            arr.push(a);
            admin.req({
              url: api.host + api.batchUpdateIsDelY,
              data: JSON.stringify(arr),
              type: "POST",
              dataType: "json",
              contentType: "application/json",
              done: function (res) {
                layer.msg(res.message);
                layui.table.reload("#LAY-app-content-list"); //重载表格
              }
            });
            // 删除
          }else if(obj.event === "delete"){
             var projectId = obj.data.tcInspId;
             var _array = [];
              _array.push(projectId);
             admin.req({
              url: api.host + api.deleteInSp_llp,
              data:JSON.stringify(_array),
              type: "POST",
              dataType: "json",
              contentType: "application/json",
              done: function (res) {
                layer.msg(res.message);
                layui.table.reload("#LAY-app-content-list"); //重载表格
              }
            });   
          }
        });
      }

      //事件
      var active = {
        // 新建项目的弹出层的
        addproduct: function () {
          admin.popup({
            title: "新建项目",
            area: ['344px', '390px'],
            scrollbar: false,
            offset: 'auto',
            move: false,
            resize: false,
            fixed: true,
            closeBtn: 0,
            btn: 0,
            shadeClose: true,
            id: "LAY-popup-user-add",
            success: function (layero, index) {
              view(this.id).render("patrol/alert/addNew_alert").done(function () {
                // 点击关闭
                $(".layui-input-block").on("click", ".btn2", function () {
                  layer.close(index);
                });

                //监听提交
                form.on("submit(layuiadmin-app-form-submit)", function (data) {
                  var ones = $("#ones").val();
                  var two = $("#two").val();
                  var three = $("#three").val();
                  var four = $("#four").val();
                  var text = $("#text").val();
                  var field = data.field; //获取提交的字段
                  var fieldOne = JSON.stringify(field);
                  if (ones != "" && two != "" && three != "" && four != "" && text != "") {
                    admin.req({
                      url: api.host + api.newProject,
                      data: fieldOne,
                      type: "POST",
                      dataType: "json",
                      contentType: "application/json",
                      done: function (res) {
                        layui.table.reload("#LAY-app-content-list"); //重载表格
                        layer.close(index); //执行关闭
                        layer.msg(res.message);
                      }
                    });
                  } else {
                    layer.msg('请填写完整哟');
                  }
                });
              });
            },
          });
          // layer.restore();
        },
        deleteProject:function(){
           var checkStatus = table.checkStatus('#LAY-app-content-list');
           if (checkStatus.data.length == 0) {
                    parent.layer.msg('至少删除一个哟！', { icon: 2 });
                    return;
            }
            var numbers_llp = [];
            for (var i = 0; i < checkStatus.data.length; i++) {
                numbers_llp.push(checkStatus.data[i].tcInspId);
            }
            admin.req({
                type: 'post',
                dataType: 'json',
                contentType: 'application/json',
                url: api.host + api.deleteInSp_llp,
                data: JSON.stringify(numbers_llp),
                success: function (data) {
                    layer.msg(data.message);
                    layui.table.reload('#LAY-app-content-list'); //重载表格  
                }
            });
        }
      };
      var _TPL = {
        tcInspIsdel: function (d) {
        if (d.tcInspIsdel == 0) {
          return "<span>启用</span>";
        } else if (d.tcInspIsdel == 1) {
          return "<span>禁用</span>";
        } 
        }
      }
      // 列定制
      utill.columnCustom('#LAY-app-content-list', "TcEamReqinspectionVO", {
        url: api.host + api.selectProjectList,
        where: {
          tcInspUnit: "",
          tcInspDsc: "",
          tcInspMax: "",
          tcInspMin: "",
          tcInspName: ""
        },
        toolbar: {
          toolbar: '#barDemo',
          title: '操作',
          event: 'detail',
          align: 'center',
        },
        templet: _TPL,
        checkbox: true
      });

      $(".layui-btn.layuiadmin-btn-useradmin").on("click", function () {
        var type = $(this).data("type");
        active[type] ? active[type].call(this) : "";
      });
    });
  </script>